package com.kzj.config;

import com.kzj.interceptor.JwtHandlerInterceptor;
import com.kzj.interceptor.MyHttpServletRequestHandlerInterceptor;
import com.kzj.interceptor.UserLoginHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Autowired
    JwtHandlerInterceptor jwtHandlerInterceptor;
    @Autowired
    MyHttpServletRequestHandlerInterceptor myHttpServletRequestHandlerInterceptor;
    @Autowired
    UserLoginHandlerInterceptor userLoginHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myHttpServletRequestHandlerInterceptor).addPathPatterns("/**");
        registry.addInterceptor(userLoginHandlerInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/common/login","/common/sendImageCode")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**","/doc.html");
//        registry.addInterceptor(jwtHandlerInterceptor).addPathPatterns("/**").excludePathPatterns("");
    }
    @Bean
    public Docket docket() {
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("web成绩管理系统")
                .version("1.0")
                .description("web成绩管理系统接口文档")
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.kzj.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
